<?php
/**
 * Description: 获取通知信息
 * User: devforma
 * Date: 15/4/9
 * Time: 16:08
 */

class GetNotifications implements iController {

    /**
     * api请求处理主函数
     * @param array $queryArgs 就是$_REQUEST变量
     * @return array api返回结果，必须含response_code
     */
    public function output($queryArgs) {
        global $cmsdb;

        if (!isset($queryArgs['offset']) || !is_numeric($queryArgs['offset'])
            || !isset($queryArgs['count']) || !is_numeric($queryArgs['count']) || $queryArgs['count'] <= 0) {
            return genOutput(1000);
        }

        $type = $queryArgs['terminal_type'] === 'iOS_phone' ? 'iOS' : 'android';

        $sql = 'SELECT * FROM `qb_notify` WHERE `terminal_type` IN ("all", "'.$type.'") AND `app_type`="dailyplan" ORDER BY `id` DESC LIMIT '.$queryArgs['offset'].', '.$queryArgs['count'];
        $notifyList = $cmsdb->getResults($sql);

        $list = array();
        foreach ($notifyList as $notify) {
            $list[] = array(
                'id' => intval($notify->id),
                'type' => $notify->notify_type,
                'title' => $notify->title,
                'content' => $notify->content,
                'status' => 'fresh'
            );
        }

        return genOutput(1, array(
            'list' => $list
        ));
    }
}